package etnorservice.etnor_service.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
public class ApiServiceUrl {

    @Autowired
    private RestTemplate restTemplate;

    public String getWeatherInfo(String apiUrl) {
        try {
            ResponseEntity<String> response = restTemplate.getForEntity(apiUrl, String.class);
            if (response.getStatusCode().is2xxSuccessful()) {
                return response.getBody();
            } else {
                // 处理错误情况
                return "Failed to fetch weather info. Status code: " + response.getStatusCodeValue();
            }
        } catch (Exception e) {
            return "Error fetching weather info: " + e.getMessage();
        }
    }
}
